/*****************************************************************************************
This file is a part of Arise library.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

Arise Engine		Font.h

					E-mail:		arise_engine@mail.ru

					Origin by:	Haaf's Game Engine 1.5, 
								Copyright (c) 2003-2004 Relish Games
								http://hge.relishgames.com

created:			02.05.2008
last changes:		05.08.2008
*****************************************************************************************/
#pragma once
#include "..\renderer\Sprite.h"
#include "..\engine\FileData.h"

#define ALIGN_TEXT_LEFT			0
#define ALIGN_TEXT_RIGHT		1
#define ALIGN_TEXT_CENTER		2
#define ALIGN_TEXT_HORZMASK		0x03

#define ALIGN_TEXT_TOP			0
#define ALIGN_TEXT_BOTTOM		4
#define ALIGN_TEXT_MIDDLE		8
#define ALIGN_TEXT_VERTMASK		0x0C

#define	FONTHD_NAME				"filename"
#define	FONTHD_SCALE			"scale"
#define	FONTHD_ROTATION			"rotation"
#define	FONTHD_TRACKING			"tracking"
#define	FONTHD_SPACING			"spacing"


struct FontHeader
{
	FontHeader()
	{
		scale		= 1;
		rotation	= 0;
		tracking	= 0;
		spacing		= 0;	
		color		= 0;
		blend		= BLEND_COLORMUL;
	}
	
	std::string	filename;
	float		scale;
	float		rotation;
	float		tracking;
	float		spacing;
	DWORD		color;
	int			blend;
};

//	Font is a helper class for rendering text with bitmap fonts

class Font
{
private:

	char		buffer[1024];
	float		fHeight;
	float		fScale;
	float		fRot;
	float		fTracking;
	float		fSpacing;
	DWORD		dwCol;
	float		fZ;
	int			nBlend;

public:
	Font();
	Font(const Font &fnt);
	~Font();

	float		pre[256];
	float		post[256];
	Sprite*		letters[256];

	Font&		operator= (const Font &fnt);

	void		Render(float x, float y, int align, const char *string);
	void		printf(float x, float y, int align, const char *format, ...);
	void		printfb(float x, float y, float w, float h, int align, const char *format, ...);

	void		SetColor(DWORD col);
	void		SetZ(float z);
	void		SetBlendMode(int blend);
	void		SetScale(float scale) {fScale=scale;}
	void		SetRotation(float rot) {fRot=rot;}
	void		SetTracking(float tracking) {fTracking=tracking;}
	void		SetSpacing(float spacing) {fSpacing=spacing;}
	void		SetHeight(float height) {fHeight = height;} 

	DWORD		GetColor() const {return dwCol;}
	float		GetZ() const {return fZ;}
	int			GetBlendMode() const {return nBlend;}
	float		GetScale() const {return fScale;}
	float		GetRotation() const {return fRot;}
	float		GetTracking() const {return fTracking;}
	float		GetSpacing() const {return fSpacing;}

	Sprite*		GetSprite(char chr) const { return letters[(unsigned char)chr]; }
	float		GetHeight() const { return fHeight; }
	float		GetStringWidth(const char *string) const;
};



/****************************************************************************************
		
		Resource script example:

*****************************************************************************************

[font]
filename	courier_new.fnt
scale		1.0
rotation	1.0
tracking	1.0
spacing		1.0
color		255 255 0 255
blend		COLORADD COLORMUL ALPHAADD

*****************************************************************************************/